<template>
  <div class="login-container">
    <video autoplay loop muted class="bg-video">
      <source src="../assets/首页.mp4" type="video/mp4">
    </video>
    <el-row type="flex" justify="center" align="middle" style="height: 100vh">
      <el-col :xs="20" :sm="12" :md="8" :lg="6" :xl="4">
        <el-form>
          <el-form-item class="text-center">
            <span class="title">充电桩运营管理平台</span>
          </el-form-item>
          <el-form-item>
            <el-input
              v-model="loginform.employeeAccount"
              placeholder="请输入账号"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-input
              v-model="loginform.loginPassword"
              show-password
              placeholder="请输入密码"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button @click="login" type="primary" style="width: 100%"
              >登录</el-button
            >
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loginform: {
        employeeAccount: "admin",
        loginPassword: "123456",
      },
    };
  },
  methods: {
    login() {
      this.$axios.post("/api/employee/login", this.loginform).then((resp) => {
        let key = resp.data.code;
        switch (key) {
          case 2001:
            this.$message({
              message: "密码或帐户错误",
              type: "error",
            });
            break;
          case 2002:
            this.$message({
              message: "密码或帐户不能为空",
              type: "error",
            });
            break;
          case 200:
            // 登录成功,在浏览器的localStorage存储jwt
            localStorage.setItem("authentication", resp.data.data.jwt);
            this.$message({
              message: "登陆成功",
              type: "success",
            });
            // 验证成功跳转路由StoreIndex,path:'/'
            this.$router.push('/home').catch(err => {
              if (err.name !== 'NavigationDuplicated') throw err
            });
            break;
        }
      });
    },
  },
};
</script>

<style scoped>
.login-container {
  position: relative;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

.bg-video {
  position: absolute;
  top: 50%;
  left: 50%;
  min-width: 100%;
  min-height: 100%;
  width: auto;
  height: auto;
  transform: translateX(-50%) translateY(-50%);
  z-index: -1;
  object-fit: cover;
}

.el-row {
  height: 100vh;
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.el-col {
  background: rgba(255, 255, 255, 0.8);
  padding: 40px 30px;
  border-radius: 8px;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  max-width: 400px;
}

.el-input {
  margin: 8px 1px;
}

.text-center {
  text-align: center;
}

.title {
  font-size: 24px;
  font-weight: 500;
  color: #303133;
}

/* 确保输入框和按钮更好看 */
:deep(.el-input__inner) {
  background: rgba(255, 255, 255, 0.9);
}

:deep(.el-button--primary) {
  background: rgba(64, 158, 255, 0.9);
  border: none;
  padding: 12px 0;
  font-size: 16px;
  transition: all 0.3s ease;
}

:deep(.el-button--primary:hover) {
  background: rgba(64, 158, 255, 1);
  transform: translateY(-2px);
}
</style>